<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.lp.cfg.ProConfig"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/WEB-INF/oss/iot/common/variable.jsp"%>
<%@ include file="/WEB-INF/oss/iot/common/variable_js.jsp"%>
<%@ include file="/WEB-INF/oss/iot/common/resource_lib.jsp"%>
<style type="text/css">
	.index_theLeft ul {
	    width: 100%;
	    padding: 0px;
	    margin: 0px;
	    overflow: auto;
	}
	.index_theLeft li {
	    list-style: none;
	    position: relative;
	     padding: 8px 0 8px 20px;
	    border-bottom: 1px solid #f9f9f9;
	    cursor: pointer;
	}
	
	.index_theLeft li.active , .index_theLeft li:HOVER{
		background: #f9f9f9;
	}
	
	.index_theLeft li span,.index_theLeft li h5{
		text-align: center;
		color: #333;
	}
	.mapContainer{
		height: 550px;width:100%;
	}
	
	.app-container{
		background:  #f2f2f2;width: 100%;border-top:1px solid #ecf0f5;
	}
	
	.box-white {
	    width: 97%;
	    min-width: 897px;
	    padding-bottom: 0;
	    margin: 0 auto;
	}
	.box {
	    padding: 10px;
	    padding-top:1px;
	    border-left: 1px solid #d2d6de;
	    border-right: 1px solid #d2d6de;
	    border-bottom: 1px solid #d2d6de;
	}
	.box {
	    border: 0!important;
	    box-shadow: 0 0 2px 1px rgba(13,5,9,.08)!important;
	}
	.box {
	    position: relative;
	    border-radius: 3px;
	    background: #fff;
	    border-top: 3px solid #d2d6de;
	    margin-bottom: 20px;
	    width: 100%;
	    box-shadow: 0 1px 1px rgba(0,0,0,.1);
	}

.sceneList-info{
	padding-top: 10px;
	padding-left: 10px;
}
	.blue-span{
		background: #3499da;
	    padding: 3px 6px;
	    color: #fff;
	    border-radius: 4px;
	}
	
	.red-span{
		background: #f44336;
	    padding: 3px 6px;
	    color: #fff;
	    border-radius: 4px;
	}
</style>
</head>
<body>
	<div>
		<div>
			<div>
				<div>
					<div class="container-layout sceneList-info" style="position: relative;">
						<div class="box join-device-box">
							<input class="node_id" type="hidden" >
							<input class="sensor_device_id" type="hidden">
							 <div style="margin-top:10px;">
								<div id="init-table" type-option="table" config-option="'url':'/page/sensor',
											param:{ node_id:'$.node_id$',data_type:-1 ,sensor_device_id: '$.sensor_device_id$' },
											columns:[
												{'name':'Serial number','type':'seq','value':'seq','width':'8%'}, 
												{'name':'Sensor name','value':'name','width':'16%'}, 
												{'name':'Type',type:'self',value_callback:'func_type_name','width':'9%'}, 
												{'name':'Address number','value':'sensor_device_id','width':'10%'}, 
												{'name':'Register number','value':'port_id','width':'10%'}, 
												{'name':'Controls','type':'self','value_callback':'value_function','width':'6%'}]" > 
								
								</div>
							</div>
						</div>
						<img title="Add sensor" alt="Add sensor"  style="cursor:pointer;width:45px;position:absolute;bottom: 10.5%;right:0%;" onclick="addSensor()"  src="<%=basePath%>/image/oss/iot/add.png">
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
function changeScene(obj){
	$(".dashboard-menu li").removeClass("active");
	$(obj).addClass("active");
	$(".scene_id").val($(".dashboard-menu li.active").attr("sid"));
	reflash( $(".dashboard-menu li.active").attr("sid"));
	// 
	manual_init_selecter($(".jui-selecter"));
}
function reflash(id){
	$("#init-table").data("params",{ scene_id: $(".scene_id").val(),data_type:-1 });
	$("#init-table").tableAdaptor();
}
function value_function(data,seq){
	return "<span tag='Editor' onclick='t_edit(this,"+data.id+")' class='self-icon icon-edit'></span>"+
    "<span tag='delete' onclick='t_delete(this,"+data.id+")' class='self-icon icon-bitbucket'></span>";
}
function t_edit(obj,id){
	var subUrl = '' ;
	var sensor_device_id = GetQueryString("sensor_device_id") ;
	if( !validater.empty( sensor_device_id ) ){
		subUrl = "&sensor_device_id=" + sensor_device_id ;
	}
	forwardUrl("/iot/sensor_info_detail?id="+ $(".node_id").val()  +"&sid="+id + subUrl );
}

function func_type_name(obj){
	if(obj.data_type == 0 ){
		return "<span class='blue-span'>data</span>" ;
	}else if(obj.data_type == 1) {
		return "<span class='red-span'>disposition</span>" ;
	}else if(obj.data_type == 2) {
		return "<span class='red-span'>Give an alarm</span>" ;
	}
}

function t_delete(obj,id){
	lcomfirm('Are you sure to delete the sensor?',function(){
		commonAjax("DELETE",localUrl+"/sensor?id="+id, "",function(){
			tip("Successfully deleted");
			setTimeout(function(){
				closeAll();
				$("#init-table").tableAdaptor();
			},1000)
		});
	});
}

function addSensor(){
	var subUrl = '' ;
	var sensor_device_id = GetQueryString("sensor_device_id") ;
	if( !validater.empty( sensor_device_id ) ){
		subUrl = "&sensor_device_id=" + sensor_device_id ;
	}
	forwardUrl("/iot/sensor_info_detail?id="+ $(".node_id").val() + subUrl )  ;
}

$(function(){
	$(".node_id").val( GetQueryString("node_id") );
	$(".sensor_device_id").val(GetQueryString("sensor_device_id")) ;
})
</script>
</html>